<template>
  <div>
    <config-list
      :edit-data="editData"
      :is-create="isCreate"
      @getFormConfigDataResult="handlerGetFormConfigData"
      ref="formConfig"
    />
  </div>
</template>

<script>
import configList from '@/components/common/FormGenerator/index/Home.vue'
import { formaAdd , formConfigEdit } from '@/api/api'
// import * as systemFormConfigApi from '@/api/systemFormConfig.js'
export default {
  name: "edit",
  components: { configList },
  props: {
    editData: {
      type: Object,
      default: {}
    },
    isCreate: {
      type: Number,
      default: 0 // 0=创建，1=编辑
    }
  },
  data() {
    return {}
  },
  methods: {
    restData(){
      this.$nextTick(()=>{
          this.$refs.formConfig.restData()
        })
    },
    handlerGetFormConfigData(formConfigData) {
      this.handlerSave(formConfigData)
    },
    async handlerSave(pram) {
      if(this.isCreate){
        const res = await formConfigEdit(pram)
        if(res.code == 200){
        this.$message.success(`编辑表单配置成功`)
          setTimeout(() => {
             this.$emit('hideDialog')
        }, 800)
      }
      }else{
        const res = await formaAdd(pram)
         if(res.code == 200){
           this.$message.success(`新增表单配置成功`)
          setTimeout(() => {
             this.$emit('hideDialog')
         }, 800)
        }
      }
      
      // systemFormConfigApi.getFormConfigSave(pram).then(data => {
      //   this.$message.success('创建表单配置成功')
      //   setTimeout(() => {
      //     this.$emit('hideDialog')
      //   }, 800)
      // })
    },
    handlerEdit(pram) {
      systemFormConfigApi.getFormConfigEdit(pram).then(data => {
        this.$message.success('编辑表单配置成功')
        setTimeout(() => {
          this.$emit('hideDialog')
        }, 800)
      })
    }
  }
}
</script>

<style scoped>

</style>
